# -*- coding: utf-8 -*-
"""
demo.py
"""
import tornado.httpserver
import tornado.ioloop
import tornado.options
import tornado.web
from tornado.options import define, options
import json
from crawler import get_api
define("port", default=8881, help="run on the given port", type=int)


class IndexHandler(tornado.web.RequestHandler):
	def get(self):
		activityId= self.get_argument('activityId', '')
		itemId = self.get_argument('itemId', '')
		if not activityId or not itemId:
			self.write('<h1>Warning: itemId or activityId not None abaa!!</h1>')
		else:
			# data = {
			# 	'activityId': activityId,
			# 	'itemId': itemId,
			# }
			data = get_api(activityId, itemId)
			self.write(data)
			# self.write(json.dumps(data))


class IndexHandler2(tornado.web.RequestHandler):
	def get(self):
		greeting = self.get_argument('aa', 'Hell00')
		self.write(greeting + ', friendly user!')


class IndexHandler3(tornado.web.RequestHandler):
	def get(self):
		greeting = self.get_argument('aa', 'blog2')
		self.write(greeting + ', friendly user!')

if __name__ == "__main__":
	handlers_list = [
		(r"/", IndexHandler), 
		# (r"/blog", IndexHandler2),
		# (r"/blog2", IndexHandler3),
		]
	tornado.options.parse_command_line()
	settings = dict(
			debug=True,
		)
	app = tornado.web.Application(handlers=handlers_list, **settings)
	http_server = tornado.httpserver.HTTPServer(app)
	http_server.listen(options.port)
	tornado.ioloop.IOLoop.instance().start()

"""
python demo.py --port=8881
end demo.py
"""